package com.cbn.ibcp.jishiting.rms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.cbn.ibcp.common.annotation.DataSource;
import com.cbn.ibcp.common.enums.DataSourceType;
import com.cbn.ibcp.jishiting.rms.domain.ResVideoEpisode;
import com.cbn.ibcp.jishiting.rms.mapper.ResVideoEpisodeMapper;
import com.cbn.ibcp.jishiting.rms.service.IResVideoEpisodeService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

@Service
@RequiredArgsConstructor
public class ResVideoEpisodeServiceImpl implements IResVideoEpisodeService {

    private final ResVideoEpisodeMapper resVideoEpisodeMapper;

    @DataSource(DataSourceType.ibcp_rms)
    @Override
    public List<ResVideoEpisode> selectListByIdAndAlbumId(Long id, Long albumId) {
        LambdaQueryWrapper<ResVideoEpisode> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (!Objects.isNull(id)) {
            lambdaQueryWrapper.eq(ResVideoEpisode::getId, id);
        }
        if (!Objects.isNull(albumId)) {
            lambdaQueryWrapper.eq(ResVideoEpisode::getAlbumId, albumId);
        }
        return resVideoEpisodeMapper.selectList(lambdaQueryWrapper);
    }


    @DataSource(DataSourceType.ibcp_rms)
    @Override
    public ResVideoEpisode selectById(Long id) {
        if (Objects.isNull(id)) {
            return null;
        }
        return resVideoEpisodeMapper.selectById(id);
    }
}
